package pub.cleangao.codegen.literal;

import pub.cleangao.codegen.GenConfigHolder;
import pub.cleangao.codegen.enquiry.TableInfo;

import java.util.HashMap;
import java.util.Map;


public class TemplateBuilder {

    private static final Map<String, Template> serviceTemplateMap = new HashMap<>();
    private static final Map<String, Template> stubTemplateMap = new HashMap<>();


    static {
        ControllerTemplate controllerTemplate = new ControllerTemplate();
        serviceTemplateMap.put(controllerTemplate.type().name(), controllerTemplate);
        ServiceTemplate serviceTemplate = new ServiceTemplate();
        serviceTemplateMap.put(serviceTemplate.type().name(), serviceTemplate);
        DaoTemplate daoTemplate = new DaoTemplate();
        serviceTemplateMap.put(daoTemplate.type().name(), daoTemplate);
        EntityTemplate entityTemplate = new EntityTemplate();
        serviceTemplateMap.put(entityTemplate.type().name(), entityTemplate);
    }

    static {
        StubApiTemplate stubApiTemplate = new StubApiTemplate();
        stubTemplateMap.put(stubApiTemplate.type().name(), stubApiTemplate);
        StubDtoTemplate stubDtoTemplate = new StubDtoTemplate();
        stubTemplateMap.put(stubDtoTemplate.type().name(), stubDtoTemplate);
    }

    public static void assembleServiceLiteral(TableInfo tableInfo, GenConfigHolder config) {
        for (Template template : serviceTemplateMap.values()) {
            template.writeOutToFile(tableInfo, config);
        }
    }

    public static void assembleStubLiteral(TableInfo tableInfo, GenConfigHolder config) {
        for (Template template : stubTemplateMap.values()) {
            template.writeOutToFile(tableInfo, config);
        }
    }


}
